package com.example.testtransition;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.WindowManager;

//import com.yidui.common.utils.RomUtils;


public final class DeviceInfo {

	// 屏幕宽度（像素）WelcomeActivity onResume之后才有值
	public static int WIDTH;

	// 屏幕高度（像素）WelcomeActivity onResume之后才有值
	public static int HEIGHT;

	public static int STATUSBAR_HEIGHT;

	public static float DENSITY;

	public static int DENSITY_DPI;

	public static float SCALED_DENSITY;

	public static boolean isFlyme4Above = false;
	public static boolean isFlyme6Above = false;
	public static boolean isMiUi6Above = false;
	public static boolean isMiUi9Above = false;
	public static boolean isAndroidMOrAbove = false;

	private DeviceInfo() {

	}

	public static void init(Context context) {
		//初始化分辨率
		initScreenInfo(context);

		initStatusBarInfo ();
	}

	// 从activity中获取
	public static void initScreenInfo(Activity activity) {
		if (activity == null)
		    return;
        try {
            DisplayMetrics dm = new DisplayMetrics();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                activity.getWindowManager().getDefaultDisplay().getRealMetrics(dm);
            } else {
                activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
            }
            WIDTH = Math.min(dm.widthPixels, dm.heightPixels);
            HEIGHT = Math.max(dm.widthPixels, dm.heightPixels);
            DENSITY = dm.density;
            DENSITY_DPI = dm.densityDpi;
            SCALED_DENSITY = dm.scaledDensity;
        } catch (Exception e) {
            e.printStackTrace();
        }
	}

	// app中先获取一次，如果获取失败再从activity中获取
	public static void initScreenInfo(Context context) {
		try {
			DisplayMetrics dm = new DisplayMetrics();
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
				((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRealMetrics(dm);
			} else {
				((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(dm);
			}
			WIDTH = Math.min(dm.widthPixels, dm.heightPixels);
			HEIGHT = Math.max(dm.widthPixels, dm.heightPixels);
			DENSITY = dm.density;
			DENSITY_DPI = dm.densityDpi;
			SCALED_DENSITY = dm.scaledDensity;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void initStatusBarInfo() {
		if (Build.VERSION.SDK_INT < 19) {
			return;
		}
		DeviceInfo.isAndroidMOrAbove = RomUtils.isAndroidMOrAbove();

		DeviceInfo.isFlyme6Above = RomUtils.isFlymeV6OrAbove();
		if (DeviceInfo.isFlyme6Above) {
			return;
		}
		DeviceInfo.isFlyme4Above = RomUtils.isFlymeV4OrAbove();
		if (DeviceInfo.isFlyme4Above) {
			return;
		}
		DeviceInfo.isMiUi9Above = RomUtils.isMIUIV9OrAbove();
		if (DeviceInfo.isMiUi9Above) {
			return;
		}
		DeviceInfo.isMiUi6Above = RomUtils.isMIUIV6OrAbove();
		if (DeviceInfo.isMiUi6Above) {
			return;
		}
	}

    public static void init() {

    }
}
